import koa from 'koa'
import router from './routes/route.js'
import path from 'path'
import helmet from 'koa-helmet'
import statics from 'koa-static'
import koaBody from 'koa-body'
import jsonutil from 'koa-json'
import cors from '@koa/cors'
import compose from 'koa-compose'
const app = new koa();

const middleware = compose(
  [
    koaBody({
      multipart: true,
      encoding: 'utf-8',
      formidable: {
        keepExtensions: true,
        maxFieldsSize: 5 * 1024 * 1024
      },
      onError: err => {
        console.log('koabody Err', err);
      }
    }),
    statics(path.join(__dirname, '../public')),
    cors(),
    jsonutil({ pretty: false, param: 'pretty' }),
    helmet(),
  ]
)

app.use(middleware)
app.use(router())
app.listen(3000)
